---
import { formatDate, getPathFromCategory } from '~/utils'
import { THEME_CONFIG } from '~/theme.config'
interface Props {
  post: Post
}

const { post } = Astro.props
const { translate: t } = Astro.locals

function getCategoryUrl(category: string) {
  return `/categories/${getPathFromCategory(category, THEME_CONFIG.category_map)}`
}
---

<article class="heti">
  <header>
    <h1 class="post-title!">
      <a href={`/posts/${post.slug}/`}>{post.data.title}</a>
    </h1>
    <div class="mt-2 text-3.5">
      <span>{post.data.author}</span>
      <span>{t('posted_at')}</span>
      <time>{formatDate(post.data.pubDate)}</time>
      {
        post.data.categories &&
          post.data.categories.map((category) => (
            <a class="ml-2.5" href={getCategoryUrl(category)}>
              # {category}
            </a>
          ))
      }
    </div>
  </header>
  <slot />
</article>
